package com.shanzmoo.core.util;

import com.shanzmoo.base.constant.RedisConstant;
import com.shanzmoo.core.constant.RedisCoreKeyPrefix;

/**
 * redis key 操作工具类
 * @author: Gzhao 2020/11/9
 */
public class RedisCoreKeyUtils {

    private static final String REDIS_ROOT_FILE = RedisConstant.REDIS_BAST_ROOT + ":core:";

    protected RedisCoreKeyUtils() {
    }

    public static String installKey(String... strs) {
        StringBuilder stb = new StringBuilder(REDIS_ROOT_FILE);
        for (String s : strs) {
            stb.append(s);
        }
        return stb.toString();
    }


    /**
     * 组装用户 jwt 令牌 key
     * @param subject
     * @return
     */
    public static String installSubectJwtKey(String subject) {
        return installKey(RedisCoreKeyPrefix.JWT, subject);
    }

    /**
     * 组装分布式锁 key
     * @param str
     * @return
     */
    public static String installLockKey(String str) {
        return installKey(RedisCoreKeyPrefix.LOCK, str);
    }

    /**
     * 组装 同一分类、品牌下的 spu 数量 key
     * @param spuNotWithIndex
     * @return
     */
    public static String installSpuIndexKey(String spuNotWithIndex) {
        return installKey(RedisCoreKeyPrefix.SPU_INDEX, spuNotWithIndex);
    }

    /**
     * 组装 同一 spu 下的sku数量 key
     * @param skuNotWithIndex
     * @return
     */
    public static String installSkuIndexKey(String skuNotWithIndex) {
        return installKey(RedisCoreKeyPrefix.SKU_INDEX, skuNotWithIndex);
    }

    /**
     * 组装 商城首页 banner 图，key
     * @return
     */
    public static String installBannerKey() {
        return installKey(RedisCoreKeyPrefix.BANNER);
    }

    /**
     * 组装 商城首页 分类，key
     * @return
     */
    public static String installIndexCategoryKey() {
        return installKey(RedisCoreKeyPrefix.INDEX_CATEGORY);
    }

    /**
     * 组装 商城首页 推荐商品 key
     * @return
     */
    public static String installRecommendSpuKey() {
        return installKey(RedisCoreKeyPrefix.RECOMMEND_SPU);
    }

    /**
     * 组装 商城 商品实际销量 key
     * @return
     */
    public static String installSpuSalesKey() {
        return installKey(RedisCoreKeyPrefix.SPU_SALES);
    }

    /**
     * 组装 商城 所有商品分类 key
     * @return
     */
    public static String installAllCategoryKey() {
        return installKey(RedisCoreKeyPrefix.ALL_CATEGORY);
    }

    /**
     * 组装 商城 所有商品spu key
     * @return
     */
    public static String installAllSpuKey() {
        return installKey(RedisCoreKeyPrefix.SPU_ALL);
    }

    /**
     * 组装 商品索引 辅助缓存 key
     *  例如：spu:search:A:assist
     * @param space 索引空间
     * @return
     */
    public static String installSpuSearchAssistKey(String space) {
        return installKey(RedisCoreKeyPrefix.SPU_SEARCH, space, ":assist");
    }

    /**
     * 组装 商品索引 缓存 key
     *  例如：spu:search:A:info
     * @param space 索引空间
     * @return
     */
    public static String installSpuSearchInfoKey(String space) {
        return installKey(RedisCoreKeyPrefix.SPU_SEARCH, space, ":info");
    }

    /**
     * 组装 商品索引空间 key
     * @return
     */
    public static String installSpuSearchActiveSpaceKey() {
        return installKey(RedisCoreKeyPrefix.SPU_SEARCH_ACTIVE_SPACE);
    }

    /**
     * 组装 商品图片 key
     * @return
     */
    public static String installSpuPictureKey() {
        return installKey(RedisCoreKeyPrefix.SPU_PICTURE);
    }

    /**
     * 组装 商品详情图片 key
     * @return
     */
    public static String installSpuInfoPictureKey() {
        return installKey(RedisCoreKeyPrefix.SPU_INFO_PICTURE);
    }

    /**
     * 组装 商品sku key
     * @param spuId
     * @return
     */
    public static String installSkuInfoKey(String spuId) {
        return installKey(RedisCoreKeyPrefix.SKU_INFO, spuId);
    }

    /**
     * 组装 会员手机验证码 key
     * @param memberId
     * @return
     */
    public static String installIdentifyingCodeKey(Integer memberId) {
        return installKey(RedisCoreKeyPrefix.IDENTIFYING_CODE, String.valueOf(memberId));
    }

    /**
     * 组装 会员token key
     * @return
     */
    public static String installMemberTokenKey() {
        return installKey(RedisCoreKeyPrefix.MEMBER_TOKEN);
    }

    /**
     * 组装 订单信息列表，key
     * @return
     */
    public static String installAllOrderListKey() {
        return installKey(RedisCoreKeyPrefix.ORDER_LIST);
    }

    /**
     * 组装 用户订单信息列表，key
     * @return
     */
    public static String installMemberOrderListKey() {
        return installKey(RedisCoreKeyPrefix.MEMBER_ORDER_LIST);
    }

    /**
     * 组装 用户订单明细列表，key
     * @return
     */
    public static String installOrderDetailListKey() {
        return installKey(RedisCoreKeyPrefix.ORDE_DETAIL_LIST);
    }

}
